package org.mathig.poker.hand;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.mathig.poker.Card;

public abstract class AbstractHand implements Hand {

	private static Comparator<Card> RANK_COMPARATOR = new Comparator<Card>() {
		public int compare(Card c1, Card c2) {
			return c1.getRank().compareTo(c2.getRank());
		}
	};

	public static int compareRanks(List<Card> cards1, List<Card> cards2) {
		Collections.sort(cards1, RANK_COMPARATOR);
		Collections.sort(cards2, RANK_COMPARATOR);
		for (int i = 0; i < cards1.size() && i < cards2.size(); i++) {
			int compare = cards1.get(i).getRank().compareTo(cards2.get(i).getRank());
			if (compare != 0)
				return compare;
		}
		return 0;
	}

	public int compareTo(Hand hand) {
		return getPokerRank().compareTo(hand.getPokerRank());
	}

	@Override
	public String toString() {
		return getClass().getSimpleName();
	}

}
